﻿using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;

namespace DapperHelper.SqlBuilder
{
    public class InsertBuilder<T> : AbstractSqlBuilder<T>
    {
        private StringBuilder FieldBuilder { get; }
        private StringBuilder ParameterBuilder { get; }

        public InsertBuilder() : base()
        {
            FieldBuilder = new StringBuilder();
            ParameterBuilder = new StringBuilder();
            FieldBuilder.Append(string.Join(",", AllField.Select(FieldName)));
            ParameterBuilder.Append(string.Join(",", AllField.Select(v => $"@{FieldName(v)}")));

            SqlBuilder.Append("insert into ").Append(TableName()).Append(" (").Append(FieldBuilder.ToString())
                .Append(")").Append(" values (").Append(ParameterBuilder.ToString()).Append(")");
        }
    }

}